import _ from "lodash";
import { emptyCol, rmCol } from "./rmCol";
// 移除多个列

export function rmCols(
  sheets: Sheet | Sheet[],
  indexs: number | number[]
): Sheet[] {
  let cols: number[] = _.isArray(indexs) ? _.sortBy(indexs) : [indexs]; // 要移除的数组
  let res: Sheet[] = [];
  if (_.isArray(sheets)) {
    _(sheets).each((sheet: Sheet) => {
      let temp: Sheet = sheet;
      let offset: number = 0; //
      _(cols).each((i) => {
        temp = rmCol(temp, i - offset);
        offset++;
      });
      res.push(temp);
    });
  } else {
    // 只传入了一个sheet
    res = rmCols([sheets], cols);
  }
  return res;
}

export function emptyCols(
  sheets: Sheet | Sheet[],
  indexs: number | number[]
): Sheet[] {
  let cols: number[] = _.isArray(indexs) ? indexs : [indexs];
  let res: Sheet[] = [];
  if (_.isArray(sheets)) {
    _(sheets).each((sheet: Sheet) => {
      let temp: Sheet = sheet;
      _(cols).each((i) => {
        temp = emptyCol(sheet, i);
      });
      res.push(temp);
    });
  } else {
    res = emptyCols([sheets], cols);
  }
  return res;
}
